package com.cht.commonUtil.svn;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cht.commonUtil.webInit.SP;
import com.cht.commonUtil.widgets.Widgets;
import com.google.gson.GsonBuilder;

public class QuerySVNfileInJsonBySubsys4Dep extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		
		response.setCharacterEncoding( SP.UIcodeSet );
		response.setContentType("application/text");
		
		String svnUrl = request.getParameter("svnUrl");
		String svnId = request.getParameter("svnId");
		String svnPwd = request.getParameter("svnPwd");
		long svnVer = Long.parseLong( request.getParameter("svnVer") );
		String res = null;
		
		try {
			Widgets wid = new Widgets();
			//受限於SVNKit 僅提供有限的 路徑搜尋，所以直接	
			res = wid.getSVN2fileTreeJSON(svnUrl+"branch/", svnId, svnPwd,svnVer,false);
		} catch (Exception e) {
			Widgets.errLog(e);
		}
		
		response.getWriter().write( new GsonBuilder().disableHtmlEscaping().create().toJson( res ).replaceAll("'", "\"") );
	}
}
